﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace OpenQuarters.WebQuarters.Core
{
    public partial class Permission : CMSEntity<Permission, long>, IEqualityComparer<Permission>
    {
        public override System.Linq.Expressions.Expression<Func<Permission, bool>> GetIDSelector(long ID)
        {
            return e => e.PermissionId == ID;
        }

        public override long GetKey(Permission Entity)
        {
            return Entity.PermissionId;
        }

        partial void OnCreated()
        {
            if (this.Value == null)
            {
                this.Value = "";
            }
        }

        public Permission SetValue(string Value)
        {
            this.Value = Value;
            return this;
        }

        public Permission SetRoleId(string RoleId)
        {
            this.RoleId = RoleId;
            return this;
        }

        public override void OnSaving()
        {
            base.OnSaving();

            this.LoggingMode = LoggingMode.Off;
        }

        #region IEqualityComparer<Permission> Members

        public bool Equals(Permission x, Permission y)
        {
            return x.Name == y.Name && x.Value == y.Value;
        }

        public int GetHashCode(Permission obj)
        {
            return Convert.ToString(obj.Name + "_" + obj.Value).GetHashCode();
        }

        #endregion
    }
}
